## formatBidsAndAsks

`formatBidsAndAsks(orderbookInfo: {base: Issue, counter: Issue}, offers: BookOffer[]): orderbook`

Returns formatted bids and asks, which make up an orderbook.

This is a static method on the `RippleAPI` class.

### Parameters

This method takes two parameters.

1. An `OrderbookInfo` object: `{ base: Issue, counter: Issue }`.
2. An array of `BookOffer` objects.

### Return Value

This method returns an object with two properties: `bids` and `asks`, each of which is an array of bids (buy orders) or asks (sell orders), respectively. (Note: the structures of `bids` and `asks` are identical.)

Object structure:

<%- renderSchema('output/get-orderbook.json') %>

**Raw order data:** The response includes a `data` property containing the raw order data. This may include `owner_funds`, `Flags`, and other fields.

For details, see the rippled method [book_offers](https://ripple.com/build/rippled-apis/#book-offers).

### Example

```javascript
const orderbookInfo = {
  "base": {
    "currency": "USD",
    "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
  },
  "counter": {
    "currency": "BTC",
    "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
  }
};

const address = 'r9cZA1mLK5R5Am25ArfXFmqgNwjZgnfk59';

return Promise.all(
  [
    this.api.request('book_offers', {
      taker_gets: RippleAPI.renameCounterpartyToIssuer(orderbookInfo.base),
      taker_pays: RippleAPI.renameCounterpartyToIssuer(orderbookInfo.counter),
      ledger_index: 'validated',
      limit: 20,
      taker: address
    }),
    this.api.request('book_offers', {
      taker_gets: RippleAPI.renameCounterpartyToIssuer(orderbookInfo.counter),
      taker_pays: RippleAPI.renameCounterpartyToIssuer(orderbookInfo.base),
      ledger_index: 'validated',
      limit: 20,
      taker: address
    })
  ]
).then((directOfferResults, reverseOfferResults) => {
  const directOffers = (directOfferResults ? directOfferResults : []).reduce((acc, res) => acc.concat(res.offers), [])
  const reverseOffers = (reverseOfferResults ? reverseOfferResults : []).reduce((acc, res) => acc.concat(res.offers), [])
  const orderbook = RippleAPI.formatBidsAndAsks(orderbookInfo, [...directOffers, ...reverseOffers]);
  console.log(JSON.stringify(orderbook, null, 2));
});
```

```
{
  "bids": [
    {
      "specification": {
        "direction": "buy",
        "quantity": {
          "currency": "USD",
          "value": "0.71800168",
          "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
        },
        "totalPrice": {
          "currency": "BTC",
          "value": "0.00016708342",
          "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
        }
      },
      "properties": {
        "maker": "rUKoQ1Zhn6c8EfPsaVa2Yx5NqaKN1JQSvq",
        "sequence": 262660,
        "makerExchangeRate": "4297.264683713081"
      },
      "data": {
        "Account": "rUKoQ1Zhn6c8EfPsaVa2Yx5NqaKN1JQSvq",
        "BookDirectory": "6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC98580F4456E6FA8239",
        "BookNode": "0000000000000000",
        "Flags": 0,
        "LedgerEntryType": "Offer",
        "OwnerNode": "000000000000001D",
        "PreviousTxnID": "16D75506C6317723FC03543130B5E0AAB13E8AD22514C1DB098BE05771C90447",
        "PreviousTxnLgrSeq": 43127860,
        "Sequence": 262660,
        "TakerGets": {
          "currency": "BTC",
          "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
          "value": "0.00016708342"
        },
        "TakerPays": {
          "currency": "USD",
          "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
          "value": "0.71800168"
        },
        "index": "DE877FB94EF892A4BCC58DB8CDE063D97AB5133201905DE6C8650B5DEA19E11B",
        "owner_funds": "0.03358376764081196",
        "quality": "4297.264683713081"
      }
    },
    {
      "specification": {
        "direction": "buy",
        "quantity": {
          "currency": "USD",
          "value": "1.6770875",
          "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
        },
        "totalPrice": {
          "currency": "BTC",
          "value": "0.00038681218",
          "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
        }
      },
      "properties": {
        "maker": "rpmL45YbZWKgp8AH8EjBSknWo5c8dNuuBM",
        "sequence": 231459,
        "makerExchangeRate": "4335.663628792661"
      },
      "data": {
        "Account": "rpmL45YbZWKgp8AH8EjBSknWo5c8dNuuBM",
        "BookDirectory": "6EAB7C172DEFA430DBFAD120FDC373B5F5AF8B191649EC98580F67435A75B355",
        "BookNode": "0000000000000000",
        "Flags": 0,
        "LedgerEntryType": "Offer",
        "OwnerNode": "0000000000000001",
        "PreviousTxnID": "F049EAFDDDA7B99970F77533743D95C9E12A16FE6C56215A0B09C32C4D23163F",
        "PreviousTxnLgrSeq": 43127094,
        "Sequence": 231459,
        "TakerGets": {
          "currency": "BTC",
          "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
          "value": "0.00038681218"
        },
        "TakerPays": {
          "currency": "USD",
          "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
          "value": "1.6770875"
        },
        "index": "3B314A51BD57601CA1509834DF9462037BF4B05AFCC1E1EFD334DB4E2D7B2AA6",
        "owner_funds": "0.03906802968738533",
        "quality": "4335.663628792661"
      }
    },
    // ... trimmed for brevity ...
  ],
  "asks": [
    {
      "specification": {
        "direction": "sell",
        "quantity": {
          "currency": "USD",
          "value": "0.71085738",
          "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
        },
        "totalPrice": {
          "currency": "BTC",
          "value": "0.00016876265",
          "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
        }
      },
      "properties": {
        "maker": "rUKoQ1Zhn6c8EfPsaVa2Yx5NqaKN1JQSvq",
        "sequence": 262664,
        "makerExchangeRate": "0.0002374071856720401"
      },
      "data": {
        "Account": "rUKoQ1Zhn6c8EfPsaVa2Yx5NqaKN1JQSvq",
        "BookDirectory": "20294C923E80A51B487EB9547B3835FD483748B170D2D0A451086F34ADB0EA11",
        "BookNode": "0000000000000000",
        "Flags": 0,
        "LedgerEntryType": "Offer",
        "OwnerNode": "000000000000001D",
        "PreviousTxnID": "54CE0B2783AF973718FAFA35E864A3C172BE488EBBB6F2852611C6DAC8893BDF",
        "PreviousTxnLgrSeq": 43127875,
        "Sequence": 262664,
        "TakerGets": {
          "currency": "USD",
          "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
          "value": "0.71085738"
        },
        "TakerPays": {
          "currency": "BTC",
          "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
          "value": "0.00016876265"
        },
        "index": "2D4ED103D6B3FEFA21BC385C53B63359F5678E5AA5429DDE6E1D8FE8B41CD6A8",
        "owner_funds": "142.8821425048244",
        "quality": "0.0002374071856720401"
      }
    },
    {
      "specification": {
        "direction": "sell",
        "quantity": {
          "currency": "USD",
          "value": "1.6438778",
          "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
        },
        "totalPrice": {
          "currency": "BTC",
          "value": "0.00039462656",
          "counterparty": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B"
        }
      },
      "properties": {
        "maker": "rpmL45YbZWKgp8AH8EjBSknWo5c8dNuuBM",
        "sequence": 231483,
        "makerExchangeRate": "0.0002400583303698121"
      },
      "data": {
        "Account": "rpmL45YbZWKgp8AH8EjBSknWo5c8dNuuBM",
        "BookDirectory": "20294C923E80A51B487EB9547B3835FD483748B170D2D0A4510887515B1216C9",
        "BookNode": "0000000000000000",
        "Flags": 0,
        "LedgerEntryType": "Offer",
        "OwnerNode": "0000000000000001",
        "PreviousTxnID": "6FA370F52C45F6149482156FF7B4226713AECE991FB7D053F74172CB0B8F24E9",
        "PreviousTxnLgrSeq": 43127158,
        "Sequence": 231483,
        "TakerGets": {
          "currency": "USD",
          "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
          "value": "1.6438778"
        },
        "TakerPays": {
          "currency": "BTC",
          "issuer": "rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",
          "value": "0.00039462656"
        },
        "index": "735F9661AD006BA0776859BE371D445555FC0815604603AC056469C16AC84AE3",
        "owner_funds": "166.0316626329364",
        "quality": "0.0002400583303698121"
      }
    },
    // ... trimmed for brevity ...
  ]
}
```
